package tech.novastar.http;

import tech.novastar.service.StoreService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * 新增库存
 */
@WebServlet("/StoreAddServlet")
public class StoreAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        int count = Integer.parseInt(request.getParameter("count"));
        StoreService storeService = new StoreService();
        storeService.addStore(name, count);
        response.sendRedirect(request.getContextPath() + "/home");
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/pages/add.jsp").forward(request, response);
    }
}

